home *** CD-ROM | disk | FTP | other *** search
- /* lsearch.c - search an ordered array of integers for a value */
- /* from the BTREE collection */
- #include "stdio.h"
-
- int lsearch(target,a,na,pwhere) /* search an array for a value */
- int target ; /* look for this value */
- int a[] ; /* the array to search */
- int na ; /* size of the array */
- int *pwhere ; /* store ending subscript here */
- {
- int i , ret ;
-
- for(i=1 ; i<na ; i=i+1 ) /* scan each element in array */
- { ret = a[i] - target ; /* compare target to array element */
- if( ret == 0 ) /* we're thru if it maches */
- break ;
- }
- *pwhere = i ; /* record where the search ended */
- return( ret ) ; /* return result of last compare */
- }
-
-
-